//
// HttpRequestInterface defines an interface for http transactions, with an
// optional number of retries, going over a specified network configuration.
//
// TODO: the class interface is not stable yet, as a few more
// getters and setters are still needed.
//
// TODO: provide a way to query how many bytes have been downloaded
// when the Send() returns so that the code doesn't have to rely on a final
// callback to update the progress information.

#ifndef LONGKEY_NET_HTTP_REQUEST_H_
#define LONGKEY_NET_HTTP_REQUEST_H_

class NetworkRequestCallback;

class HttpRequestInterface {
public:
	virtual ~HttpRequestInterface() {}

	virtual HRESULT Close() = 0;

	// Sends a fault-tolerant http request. Returns S_OK if the http transaction
	// went through and the correct response is available.
	virtual HRESULT Send() = 0;

	virtual HRESULT Cancel() = 0;

	virtual HRESULT Pause() = 0;

	virtual HRESULT Resume() = 0;

	virtual std::vector<uint8> GetResponse() const = 0;

	virtual int GetHttpStatusCode() const = 0;

	virtual HRESULT QueryHeadersString(uint32 info_level,
		const TCHAR* name,
		CString* value) const = 0;

	virtual CString GetResponseHeaders() const = 0;

	virtual CString ToString() const = 0;

	virtual void set_session_handle(HINTERNET session_handle) = 0;

	virtual void set_url(const CString& url) = 0;

	virtual void set_request_buffer(const void* buffer, size_t buffer_length) = 0;

	virtual void set_proxy_configuration(const ProxyConfig& proxy_config) = 0;

	// Sets the filename to receive the response instead of the memory buffer.
	virtual void set_filename(const CString& filename) = 0;

	virtual void set_low_priority(bool low_priority) = 0;

	virtual void set_callback(NetworkRequestCallback* callback) = 0;

	virtual void set_additional_headers(const CString& additional_headers) = 0;

	virtual void set_preserve_protocol(bool preserve_protocol) = 0;

	// Gets the user agent for this http request. The default user agent has
	// the following format: Google Update/a.b.c.d;req1;req2 where a.b.c.d is
	// the version of the client code and req1, req2,... are appended by
	// different http requests. For example:
	//    User-Agent: Google Update/1.2.15.0;winhttp;cup
	// indicates a WinHTTP+CUP request.
	virtual CString user_agent() const = 0;

	virtual void set_user_agent(const CString& user_agent) = 0;

	virtual void set_proxy_auth_config(const ProxyAuthConfig& config) = 0;
};

#endif	// LONGKEY_NET_HTTP_REQUEST_H_